package com.wise.service.cms.content.successarticle;

import com.wise.entities.content.SuccessArticle;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoList;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author Pitaya
 * @date 2019-11-29
 */
public class ArticleTools {
    /**
     * 如果别名为空字符串，转换为null
     *
     * @param alias 别名
     * @return 转换结果
     */
    public static String toNullAlias(String alias) {
        return "".equals(alias) ? null : alias;
    }

    /**
     * 判断别名alias是否重复
     *
     * @param alias 别名
     * @return true:重复  false:不重复
     */
    public static boolean checkAlias(String alias) {
        if (!StringUtils.isEmpty(alias)) {
            SqlSelect checkAlias = SqlSelect.selec("*").fromClassName(SuccessArticle.class)
                    .eq(SuccessArticle.ALIAS, alias);
            List<SuccessArticle> decorates = DaoList.s(SuccessArticle.class, checkAlias);
            return !decorates.isEmpty();
        } else {
            return false;
        }
    }


//    public static boolean checkApplicationAlias(String alias) {
//        if (!StringUtils.isEmpty(alias)) {
//            SqlSelect checkAlias = SqlSelect.selec("*").fromClassName(ApplicationArticle.class)
//                    .eq(ApplicationArticle.ALIAS, alias);
//            List<ApplicationArticle> decorates = DaoList.s(ApplicationArticle.class, checkAlias);
//            return !decorates.isEmpty();
//        } else {
//            return false;
//        }
//    }
}
